package com.hwhp.service.console.impl;

import java.util.ArrayList;
import java.util.List;

import com.hwhp.common.Pager;
import com.hwhp.dao.BaseDao;
import com.hwhp.dao.console.PositionDao;
import com.hwhp.entity.SPosition;
import com.hwhp.service.console.SPositionService;

public class SPositionServiceImpl implements SPositionService{
	//private PositionDao positionDao = null ;
	
	private BaseDao baseDao = null ;
	
	public boolean deletePosition(SPosition sp){
		boolean success = false ;
		try {
			success = baseDao.delete(sp);
		} catch (Exception e) {
			success = false ;
			e.printStackTrace();
		}
		//success = positionDao.deletePosition(sp);
		return success;
	}

	
	public boolean editPosition(SPosition sp) {
		boolean success = false ;
		//success = positionDao.editPosition(sp);
		try{
			baseDao.update(sp);
			success = true ;
		}catch(Exception e ){
			success = false ;
			e.printStackTrace();
		}
		return success;
	}

	
	public SPosition getSposition(String spId) {
		SPosition sp = new SPosition();
//		sp = positionDao.getSposition(spId);
		sp = (SPosition)baseDao.get(SPosition.class, spId);
		return sp;
	}

	
	public boolean insertPosition(SPosition sp) {
		boolean success = false ;
		//success = positionDao.insertPosition(sp);
		try{
			baseDao.update(sp);
			success = true ;
		}catch(Exception e){
			success = false ;
			e.printStackTrace();
		}
		// TODO Auto-generated method stub
		return success;
	}

	
	public Pager queryByPager(String hql, int pageSize, int pageNum) {
		Pager page = new Pager();
		 try {
			page = baseDao.queryByPage(hql, pageNum, pageSize);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//page = baseDao.queryByPager(hql, pageSize, pageNum);
		
		return page;
	}

	
//	public void setPositionDao(PositionDao positionDao) {
//		this.positionDao = positionDao;
//	}
//
//	
//	public PositionDao getPositionDao() {
//		return positionDao;
//	}


	public List getAllPs() {
		List psList = new ArrayList();
		String hql = "from SPosition as sp";
		psList = baseDao.query(hql);
		//psList = positionDao.getAllPosts();
		return psList;
	}


//	public boolean deletePosition(Class claz, String spId) {
//		boolean success = false ;
//		success = positionDao.deletePosition(claz, spId);
//		return success;
//	}


	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}


	public BaseDao getBaseDao() {
		return baseDao;
	}

	
}
